package com.example.springboot11.service;

import com.example.springboot11.dao.UserDao;
import com.example.springboot11.entity.User;
import com.example.springboot11.utils.JwtUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Resource
    private UserDao userDao;
    @Resource
    private JwtUtils jwtUtils;

    public String authentication(String name,String password) throws Exception{
        User user= userDao.findByName(name);
        if (user == null || !password.equals(user.getPassword()))
            throw new Exception();
        return jwtUtils.generateToken(name);

    }
}

